#include <stdio.h>

int countdigit(int n,int digit)
{
    int f;
    int count = 0;

if(n<0)
    n=-n;
    do {
        f = n % 10;
        n = n / 10;
        if (f == digit)
        {
            count++;}


        }while (n != 0);



    return count;

}
int main()
{int n;int digit;
    scanf("%d", &n);
    scanf("%d", &digit);

    printf("%d", countdigit(n,digit));

    return 0;
}
